<template>
    
    <div style="margin-top: 20px;">
        <!-- 深加工信息 -->
        <div >
            <div>
                <h3 style="font-weight: bold;color:deepskyblue;float: left;margin-right: 20px">深加工信息</h3>
                <el-button style="float:left;" @click="addInfo">设置</el-button>
            </div>
            <br><br><hr><br>
            <div style="float: left;width: 300px;">
                <h4>班组 : {{ data.piTeam }}</h4>
            </div>
            <div style="float: left;">
                <h4>负责人 : {{ data.piPeople }}</h4>
            </div>
            <br><br>

        </div>
        
        <!-- 食品安全信息 -->
        <div :style="computedHeight">
            <div>
                <h3 style="font-weight: bold;color:deepskyblue;">食品安全信息</h3>
            </div>
            <br><hr><br>
            <div>
              <el-upload v-model:file-list="fileList" :action="lis" list-type="picture-card"
                        :on-preview="handlePictureCardPreview" :on-success="handleUploadSuccess"
                        :on-error="handleUploadError" :on-remove="handleRemove">
                        <el-icon><Plus /></el-icon>
                    </el-upload>

                    <el-dialog v-model="dialogVisible" >
                        <img w-full  style="width: 80%; height: 80%;" :src="dialogImageUrl" alt="Preview Image"/>
                    </el-dialog>
            </div>
        </div>

        
        <!-- 供应商信息 -->
        <div style="float:left;width: 100%;">
          <br>
            <div>
                <h3 style="font-weight: bold;color:deepskyblue;float: left;margin-right: 20px">供应商信息</h3>
            </div>
            <br><br><hr><br>
            <!-- 原料 -->
            <div style="float: left;">
                <div>
                    <h3 style="font-weight: bold;float: left;margin-right: 20px;border-left: 4px solid deepskyblue; padding-left: 10px;">原料</h3>
                    <el-button style="float:left;" @click="addInfoyzs">设置</el-button>
                </div><br><br>
                <div style="float: left;width: 300px;margin-left: 15px;">
                    <h4>生产批次 : {{ pc}}</h4>
                </div>
                <br>
                <div style="margin-left: 15px;">
                    <!-- 原料相关材料 -->
                    
                    <!-- 原料相关材料 -->
                    <div :style="computedHeightqy3">
                      <br>
                        <div>
                            <h3 style="font-weight: bold;color:deepskyblue;">相关材料</h3>
                        </div>
                        <br><hr><br>
                        <div>
                          <el-upload v-model:file-list="fileListqy3" :action="lisqy3" list-type="picture-card"
                                    :on-preview="handlePictureCardPreviewqy3" :on-success="handleUploadSuccessqy3"
                                    :on-error="handleUploadErrorqy3" :on-remove="handleRemoveqy3">
                                    <el-icon><Plus /></el-icon>
                                </el-upload>

                                <el-dialog v-model="dialogVisibleqy3">
                                    <img w-full style="width: 80%; height: 80%;" :src="dialogImageUrlqy3" alt="Preview Image"/>
                                </el-dialog>
                        </div>
                    </div>
                </div>
            </div>


            <!-- 辅料 -->
            <div style="float: left;width:100%">
                <div>
                    <h3 style="font-weight: bold;float: left;margin-right: 20px;border-left: 4px solid deepskyblue; padding-left: 10px;">辅料</h3>
                    <el-button style="float:left;" @click="addInfoyzs">设置</el-button>
                    <br>
                </div><br>
                <div style="margin-left: 15px;">
                    <h4>生产批次 : {{ pc}}</h4>
                </div>
                <br>
                <div style="margin-left: 15px;width: 100%;">
                    <!-- 辅料相关材料 -->
                    <div :style="computedHeightqy4">
                      
                        <div>
                            <h3 style="font-weight: bold;color:deepskyblue;">相关材料</h3>
                        </div>
                        <br><hr><br>
                        <div>
                          <el-upload v-model:file-list="fileListqy4" :action="lisqy4" list-type="picture-card"
                                    :on-preview="handlePictureCardPreviewqy4" :on-success="handleUploadSuccessqy4"
                                    :on-error="handleUploadErrorqy4" :on-remove="handleRemoveqy4">
                                    <el-icon><Plus /></el-icon>
                                </el-upload>

                                <el-dialog v-model="dialogVisibleqy4">
                                    <img w-full style="width: 80%; height: 80%;" :src="dialogImageUrlqy4" alt="Preview Image"/>
                                </el-dialog>
                        </div>
                    </div>
                </div>
            </div>

            
            <!-- 添加剂 -->
            <div style="float: left;width:100%">
                <div>
                    <h3 style="font-weight: bold;float: left;margin-right: 20px;border-left: 4px solid deepskyblue; padding-left: 10px;">添加剂</h3>
                    <el-button style="float:left;" @click="addInfoyzs">设置</el-button>
                    <br>
                </div><br>
                <div style="margin-left: 15px;">
                    <h4>生产批次 : {{ pc}}</h4>
                </div>
                <br>
                <div style="margin-left: 15px;width: 100%;">
                    <!-- 添加剂相关材料 -->
                    <div :style="computedHeightqy5">
                      
                        <div>
                            <h3 style="font-weight: bold;color:deepskyblue;">相关材料</h3>
                        </div>
                        <br><hr><br>
                        <div>
                          <el-upload v-model:file-list="fileListqy5" :action="lisqy5" list-type="picture-card"
                                    :on-preview="handlePictureCardPreviewqy5" :on-success="handleUploadSuccessqy5"
                                    :on-error="handleUploadErrorqy5" :on-remove="handleRemoveqy5">
                                    <el-icon><Plus /></el-icon>
                                </el-upload>

                                <el-dialog v-model="dialogVisibleqy5">
                                    <img w-full style="width: 80%; height: 80%;" :src="dialogImageUrlqy5" alt="Preview Image"/>
                                </el-dialog>
                        </div>
                    </div>
                </div>
            </div>

            
            <!-- 包材 -->
            <div style="float: left;width:100%">
                <div>
                    <h3 style="font-weight: bold;float: left;margin-right: 20px;border-left: 4px solid deepskyblue; padding-left: 10px;">包材</h3>
                    <el-button style="float:left;" @click="addInfoyzs">设置</el-button>
                    <br>
                </div><br>
                <div style="margin-left: 15px;">
                    <h4>生产批次 : {{ pc}}</h4>
                </div>
                <br>
                <div style="margin-left: 15px;width: 100%;">
                    <!-- 包材相关材料 -->
                    <div :style="computedHeightqy6">
                      
                        <div>
                            <h3 style="font-weight: bold;color:deepskyblue;">相关材料</h3>
                        </div>
                        <br><hr><br>
                        <div>
                          <el-upload v-model:file-list="fileListqy6" :action="lisqy6" list-type="picture-card"
                                    :on-preview="handlePictureCardPreviewqy6" :on-success="handleUploadSuccessqy6"
                                    :on-error="handleUploadErrorqy6" :on-remove="handleRemoveqy6">
                                    <el-icon><Plus /></el-icon>
                                </el-upload>

                                <el-dialog v-model="dialogVisibleqy6">
                                    <img w-full style="width: 80%; height: 80%;" :src="dialogImageUrlqy6" alt="Preview Image"/>
                                </el-dialog>
                        </div>
                    </div>
                </div>
            </div>


        </div>

        
        <!-- 企业信息 -->
        <div style="float:left;width: 100%;">
            <div>
                <h3 style="font-weight: bold;color:deepskyblue;float: left;margin-right: 20px">企业信息</h3>
                <el-button style="float:left;" @click="addInfoqy">设置</el-button>
            </div>
            <br><br><hr><br>
            <div style="float: left;width: 300px;">
                <h4>公司名称 : {{ dataqy.pqyName }}</h4>
            </div>
            <div style="float: left;">
                <h4>生产许可证号 : {{ sc }}</h4>
            </div>
            <br><br>

        </div>

        
        <!-- 企业照片 -->
        <div :style="computedHeightq">
            <div>
                <h3 style="font-weight: bold;color:deepskyblue;">企业照片</h3>
            </div>
            <br><hr><br>
            <div>
              <el-upload v-model:file-list="fileListq" :action="lisq" list-type="picture-card"
                        :on-preview="handlePictureCardPreviewq" :on-success="handleUploadSuccessq"
                        :on-error="handleUploadErrorq" :on-remove="handleRemoveq">
                        <el-icon><Plus /></el-icon>
                    </el-upload>

                    <el-dialog v-model="dialogVisibleq" >
                        <img w-full  style="width: 80%; height: 80%;" :src="dialogImageUrlq" alt="Preview Image"/>
                    </el-dialog>
            </div>
        </div>


    </div>
    

    <!-- 设置深加工信息 -->
  <el-dialog v-model="addshow" title="深加工信息" style="max-width: 600px;height: 450px">
    <el-form ref="ruleFormRef" style="max-width: 100%;height: 100px" :model="input"
    :rules="rules" label-width="auto" class="demo-ruleForm" :size="formSize"
    status-icon >
    <el-form-item label="班组" prop="piTeam">
      <el-input v-model="input.piTeam" />
    </el-form-item>
    <el-form-item label="负责人" prop="piPeople">
      <el-input v-model="input.piPeople" />
    </el-form-item>
    <br><hr><br>
    <el-form-item style="float:right;">
      <el-button type="primary" @click="adds(ruleFormRef)">
        保存
      </el-button>
    </el-form-item>
  </el-form>
  </el-dialog>


    <!-- 生产批次 -->
    <el-dialog v-model="updshowpc" title="生产批次" style="max-width: 600px;height: 450px">
    <el-form ref="ruleFormRef" style="max-width: 100%;height: 100px"
    :rules="rules" label-width="auto" class="demo-ruleForm" :size="formSize"
    status-icon >
    <el-form-item label="生产批次" prop="pc">
      <el-input v-model="pcs" />
    </el-form-item>
    <br><hr><br>
    <el-form-item style="float:right;">
      <el-button type="primary" @click="addspc(ruleFormRef)">
        保存
      </el-button>
    </el-form-item>
  </el-form>
  </el-dialog>

  
    <!-- 设置企业信息 -->
    <el-dialog v-model="addshowqy" title="企业信息" style="max-width: 600px;height: 450px">
    <el-form ref="ruleFormRef" style="max-width: 100%;height: 100px" :model="inputqy"
    :rules="rulesqy" label-width="auto" class="demo-ruleForm" :size="formSizeqy"
    status-icon >
    <el-form-item label="公司名称" prop="tmBatch">
      <el-input v-model="inputqy.pqyName" />
    </el-form-item>
    <el-form-item label="生产许可证号" prop="siWeigth">
      <el-input v-model="inputqy.tmProduction" />
    </el-form-item>
    <br><hr><br>
    <el-form-item style="float:right;">
      <el-button type="primary" @click="addsqy(ruleFormRef)">
        保存
      </el-button>
    </el-form-item>
  </el-form>
  </el-dialog>

  


</template>
<script lang="ts" setup>
import{ref,onMounted,reactive,inject,computed } from 'vue'
import { type AxiosStatic } from 'axios';
const axios=inject('axios') as AxiosStatic
import { ElMessage,ElMessageBox } from 'element-plus'
import type { ComponentSize, FormInstance, FormRules } from 'element-plus'

onMounted(()=>{
    //console.log(localStorage.getItem('tmid'))
    Infoshows()//深加工信息
    shows()//食品安全信息
    showsqy3()//食品安全信息
    showsqy4()//辅料相关材料
    showsqy5()//添加剂相关材料
    showsqy6()//包材相关材料
    Infoshowsqy()//深加工企业
    showsq()//企业图片
})
// #region 深加工信息
const data=ref({})
//显示深加工信息
const Infoshows=()=>{
    axios.get('/Processing/GetProcessingInfo?tmid='+localStorage.getItem('tmid'))
    .then((res)=>{
        //console.log(res.data,res.data.length,localStorage.getItem('pc'))
        if(res.data.length>0){
            data.value=res.data[0]
        }
        //console.log(data.value)
    })
}

const input=reactive({
    piTeam: "",
    piPeople: "",
    pIid:'',
  tMid:localStorage.getItem('tmid')
})
//是否打开深加工信息
const addshow=ref(false)
//打开深加工信息弹框
const addInfo=()=>{
    //console.log(data.value.ciFeedPeople)
    addshow.value=true
    if(data.value.piTeam!=null){
            input.piTeam=data.value.piTeam
            input.piPeople=data.value.piPeople
            input.pIid=data.value.pIid
            input.tMid=data.value.tMid
        }
}


const formSize = ref<ComponentSize>('default')
const ruleFormRef = ref<FormInstance>()
//非空
const rules = reactive<FormRules<RuleForm>>({
    piTeam: [
    { required: true, message: '班组不能为空', trigger: 'blur' },
  ],
  piPeople: [
    { required: true, message: '负责人不能为空', trigger: 'blur' },
  ],
})
const adds = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
            axios.post('/Processing/AddProcessingInfo',input)
            .then((res)=>{
                //console.log(res.data)
                if(res.data>0){
                    ElMessage({
                        message: '保存成功',
                        type: 'success',
                    })
                    addshow.value=false
                    Infoshows()
                }
            })
    } else {
      console.log('error submit!', fields)
    }
  })
}

// #endregion

//#region 食品安全信息


const num=ref([])
//图片
const fileList = ref<UploadUserFile[]>([])
//显示
const shows=()=>{
    axios.get('/Processing/GetProcessingImg?tmid='+localStorage.getItem('tmid'))
    .then((res)=>{
        //console.log(res.data)
        num.value=res.data.length
        if (Array.isArray(res.data)) {
        fileList.value = res.data.map((image) => ({
          name: image.pImgId ,  
          url: image.pImgurl
        }));
      } else {
        console.error('Unexpected response data format:', res.data);
      }
    })
}
const computedHeight=computed(()=> {
    shows()
    return {
        height: num.value < 7 ? '230px' : '390px', // 直接返回字符串
        alignItems: 'center',
        margin: '0 auto',
        float: 'left',
        width: '100%',
      };
    })

const lis = computed(() => {
  return fileList.value.length > 9 ? '' : 'http://182.92.209.50:8001/api/TraceManage/GetImage';
});
// 判断是否禁用上传按钮
//const isUploadDisabled = computed(() => fileList.value.length > 9);
const dialogImageUrl = ref('')
const dialogVisible = ref(false)
//删除图片
const handleRemove: UploadProps['onRemove'] = (url) => {
  console.log(url.name)
    axios.post('/Processing/DelProcessingImg?ids='+url.name)
    .then((res)=>{
        //console.log(res.data,num.value)
        if(num.value==7){
          shows()//相关资质
      }
    })
}
//预览图片处理事件
const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
  dialogImageUrl.value = uploadFile.url!
  dialogVisible.value = true
}
//上传成功后
const handleUploadSuccess=(url)=>{
  //console.log(url)
  axios.post('/Processing/AddProcessingImg',{
    tMid:localStorage.getItem('tmid'),
    pImgurl:url,
    addName:"张三"
  })
  .then((res)=>{
    //console.log(res.data)
    if(num.value==6){
    shows()//动检证
    }
  })
}
//上传失败
const handleUploadError = (err) => {
    shows()
    if(num.value==9){
        ElMessage.error(`最多上传9张图片`);
    }else{
        ElMessage.error(`图片上传失败，请重试！`);
    }
};

//#endregion

// #region 供应商信息
//批次
const pc=ref(localStorage.getItem('pc'))
const updshowpc=ref(false)
const pcs=ref('')
const addInfoyzs=()=>{
    updshowpc.value=true
    pcs.value=pc.value
}
const addspc=()=>{
    axios.post('/Processing/Updpc?pc='+pcs.value+'&tMid='+localStorage.getItem('tmid'))
    .then((res)=>{
        localStorage.removeItem('pc')
        localStorage.setItem('pc',pcs.value)
        //console.log(res.data)
        if(res.data>0){
            ElMessage({
                message: '保存成功',
                type: 'success',
            })
            updshowpc.value=false
            window.location.reload()
        }
    })
}


//#region 原料相关材料

const numqy3=ref([])
//图片
const fileListqy3 = ref<UploadUserFile[]>([])
//显示
const showsqy3=()=>{
    axios.get('/Processing/GetProcessingImg2?tmid='+localStorage.getItem('tmid'))
    .then((res)=>{
        //console.log(res.data)
        numqy3.value=res.data.length
        if (Array.isArray(res.data)) {
        fileListqy3.value = res.data.map((image) => ({
          name: image.pImgId || 'default-name.jpeg',  // 根据需要设置图片名称
          url: image.pImgurl
        }));
      } else {
        console.error('Unexpected response data format:', res.data);
      }
    })
}
const computedHeightqy3=computed(()=> {
    showsqy3()
    return {
        height: numqy3.value < 7 ? '260px' : '410px', // 直接返回字符串
        alignItems: 'center',
        margin: '0 auto',
        float: 'left',
        width: '100%',
        // background: 'aqua'
      };
    })

const lisqy3 = computed(() => {
  return fileListqy3.value.length > 9 ? '' : 'http://182.92.209.50:8001/api/TraceManage/GetImage';
});
// 判断是否禁用上传按钮
//const isUploadDisabled = computed(() => fileList.value.length > 9);
const dialogImageUrlqy3 = ref('')
const dialogVisibleqy3 = ref(false)
//删除图片
const handleRemoveqy3: UploadProps['onRemove'] = (url) => {
  //console.log(url.name)
    axios.post('/Processing/DelProcessingImg?ids='+url.name)
    .then((res)=>{
        //console.log(res.data,num.value)
        if(numqy3.value==7){
          showsqy3()//企业图片
      }
    })
}
//预览图片处理事件
const handlePictureCardPreviewqy3: UploadProps['onPreview'] = (uploadFile) => {
  dialogImageUrlqy3.value = uploadFile.url!
  dialogVisibleqy3.value = true
}
//上传成功后
const handleUploadSuccessqy3=(url)=>{
  //console.log(url)
  axios.post('/Processing/AddProcessingImg2',{
    tMid:localStorage.getItem('tmid'),
    pImgurl:url,
    addName:"张三"
  })
  .then((res)=>{
    //console.log(res.data)
    if(numqy3.value==6){
          showsqy3()//企业图片
    }
  })
}
//上传失败
const handleUploadErrorqy3 = (err) => {
    shows3()
    if(numqy3.value==9){
        ElMessage.error(`最多上传9张图片`);
    }else{
        ElMessage.error(`最多上传9张图片！`);
    }
};

//#endregion


//#region 辅料相关材料

const numqy4=ref([])
//图片
const fileListqy4 = ref<UploadUserFile[]>([])
//显示
const showsqy4=()=>{
    axios.get('/Processing/GetProcessingImg3?tmid='+localStorage.getItem('tmid'))
    .then((res)=>{
        //console.log(res.data)
        numqy4.value=res.data.length
        if (Array.isArray(res.data)) {
        fileListqy4.value = res.data.map((image) => ({
          name: image.pImgId || 'default-name.jpeg',  // 根据需要设置图片名称
          url: image.pImgurl
        }));
      } else {
        console.error('Unexpected response data format:', res.data);
      }
    })
}
const computedHeightqy4=computed(()=> {
    showsqy4()
    return {
        height: numqy4.value < 7 ? '260px' : '410px', // 直接返回字符串
        alignItems: 'center',
        margin: '0 auto',
        float: 'left',
        width: '100%',
        // background: 'aqua'
      };
    })

const lisqy4 = computed(() => {
  return fileListqy4.value.length > 9 ? '' : 'http://182.92.209.50:8001/api/TraceManage/GetImage';
});
// 判断是否禁用上传按钮
//const isUploadDisabled = computed(() => fileList.value.length > 9);
const dialogImageUrlqy4 = ref('')
const dialogVisibleqy4 = ref(false)
//删除图片
const handleRemoveqy4: UploadProps['onRemove'] = (url) => {
  //console.log(url.name)
    axios.post('/Processing/DelProcessingImg?ids='+url.name)
    .then((res)=>{
        //console.log(res.data,num.value)
        if(numqy4.value==7){
          showsqy4()
      }
    })
}
//预览图片处理事件
const handlePictureCardPreviewqy4: UploadProps['onPreview'] = (uploadFile) => {
  dialogImageUrlqy4.value = uploadFile.url!
  dialogVisibleqy4.value = true
}
//上传成功后
const handleUploadSuccessqy4=(url)=>{
  //console.log(url)
  axios.post('/Processing/AddProcessingImg3',{
    tMid:localStorage.getItem('tmid'),
    pImgurl:url,
    addName:"张三"
  })
  .then((res)=>{
    //console.log(res.data)
    if(numqy4.value==6){
          showsqy4()
    }
  })
}
//上传失败
const handleUploadErrorqy4 = (err) => {
    shows4()
    if(numqy4.value==9){
        ElMessage.error(`最多上传9张图片`);
    }else{
        ElMessage.error(`最多上传9张图片！`);
    }
};

//#endregion


//#region 添加剂相关材料

const numqy5=ref([])
//图片
const fileListqy5 = ref<UploadUserFile[]>([])
//显示
const showsqy5=()=>{
    axios.get('/Processing/GetProcessingImg4?tmid='+localStorage.getItem('tmid'))
    .then((res)=>{
        //console.log(res.data)
        numqy5.value=res.data.length
        if (Array.isArray(res.data)) {
        fileListqy5.value = res.data.map((image) => ({
          name: image.pImgId || 'default-name.jpeg',  // 根据需要设置图片名称
          url: image.pImgurl
        }));
      } else {
        console.error('Unexpected response data format:', res.data);
      }
    })
}
const computedHeightqy5=computed(()=> {
    showsqy5()
    return {
        height: numqy5.value < 7 ? '260px' : '410px', // 直接返回字符串
        alignItems: 'center',
        margin: '0 auto',
        float: 'left',
        width: '100%',
        // background: 'aqua'
      };
    })

const lisqy5 = computed(() => {
  return fileListqy5.value.length > 9 ? '' : 'http://182.92.209.50:8001/api/TraceManage/GetImage';
});
// 判断是否禁用上传按钮
//const isUploadDisabled = computed(() => fileList.value.length > 9);
const dialogImageUrlqy5 = ref('')
const dialogVisibleqy5 = ref(false)
//删除图片
const handleRemoveqy5: UploadProps['onRemove'] = (url) => {
  //console.log(url.name)
    axios.post('/Processing/DelProcessingImg?ids='+url.name)
    .then((res)=>{
        //console.log(res.data,num.value)
        if(numqy5.value==7){
          showsqy5()
      }
    })
}
//预览图片处理事件
const handlePictureCardPreviewqy5: UploadProps['onPreview'] = (uploadFile) => {
  dialogImageUrlqy5.value = uploadFile.url!
  dialogVisibleqy5.value = true
}
//上传成功后
const handleUploadSuccessqy5=(url)=>{
  //console.log(url)
  axios.post('/Processing/AddProcessingImg4',{
    tMid:localStorage.getItem('tmid'),
    pImgurl:url,
    addName:"张三"
  })
  .then((res)=>{
    //console.log(res.data)
    if(numqy5.value==6){
          showsqy5()
    }
  })
}
//上传失败
const handleUploadErrorqy5 = (err) => {
    shows5()
    if(numqy5.value==9){
        ElMessage.error(`最多上传9张图片`);
    }else{
        ElMessage.error(`最多上传9张图片！`);
    }
};

//#endregion


//#region 包材相关材料

const numqy6=ref([])
//图片
const fileListqy6 = ref<UploadUserFile[]>([])
//显示
const showsqy6=()=>{
    axios.get('/Processing/GetProcessingImg5?tmid='+localStorage.getItem('tmid'))
    .then((res)=>{
        //console.log(res.data)
        numqy6.value=res.data.length
        if (Array.isArray(res.data)) {
        fileListqy6.value = res.data.map((image) => ({
          name: image.pImgId || 'default-name.jpeg',  // 根据需要设置图片名称
          url: image.pImgurl
        }));
      } else {
        console.error('Unexpected response data format:', res.data);
      }
    })
}
const computedHeightqy6=computed(()=> {
    showsqy6()
    return {
        height: numqy6.value < 7 ? '260px' : '410px', // 直接返回字符串
        alignItems: 'center',
        margin: '0 auto',
        float: 'left',
        width: '100%',
        // background: 'aqua'
      };
    })

const lisqy6 = computed(() => {
  return fileListqy6.value.length > 9 ? '' : 'http://182.92.209.50:8001/api/TraceManage/GetImage';
});
// 判断是否禁用上传按钮
//const isUploadDisabled = computed(() => fileList.value.length > 9);
const dialogImageUrlqy6 = ref('')
const dialogVisibleqy6 = ref(false)
//删除图片
const handleRemoveqy6: UploadProps['onRemove'] = (url) => {
  //console.log(url.name)
    axios.post('/Processing/DelProcessingImg?ids='+url.name)
    .then((res)=>{
        //console.log(res.data,num.value)
        if(numqy6.value==7){
          showsqy6()
      }
    })
}
//预览图片处理事件
const handlePictureCardPreviewqy6: UploadProps['onPreview'] = (uploadFile) => {
  dialogImageUrlqy6.value = uploadFile.url!
  dialogVisibleqy6.value = true
}
//上传成功后
const handleUploadSuccessqy6=(url)=>{
  //console.log(url)
  axios.post('/Processing/AddProcessingImg5',{
    tMid:localStorage.getItem('tmid'),
    pImgurl:url,
    addName:"张三"
  })
  .then((res)=>{
    //console.log(res.data)
    if(numqy6.value==6){
          showsqy6()
    }
  })
}
//上传失败
const handleUploadErrorqy6 = (err) => {
    shows6()
    if(numqy6.value==9){
        ElMessage.error(`最多上传9张图片`);
    }else{
        ElMessage.error(`最多上传9张图片！`);
    }
};

//#endregion



//#endregion


// #region 企业信息
const dataqy=ref({})
const sc=ref('')
//显示企业信息
const Infoshowsqy=()=>{
    axios.get('/Processing/GetProcessingQY?tmid='+localStorage.getItem('tmid'))
    .then((res)=>{
        console.log(res.data,res.data.length,localStorage.getItem('sc'))
        if(res.data.length>0){
            dataqy.value=res.data[0]
        }
            sc.value=localStorage.getItem('sc')
            //console.log(pc.value)
        
        //console.log(data.value)
    })
}

const inputqy=reactive({
    pqyName: "",
    pqYid: "",
    tmProduction: "",
  tMid:localStorage.getItem('tmid')
})
//是否打开企业信息
const addshowqy=ref(false)
//打开企业信息弹框
const addInfoqy=()=>{
    //console.log(data.value.ciFeedPeople)
    addshowqy.value=true
    if(dataqy.value.pqyName!=null){
            inputqy.pqyName=dataqy.value.pqyName
            inputqy.pqYid=dataqy.value.pqYid
            inputqy.tmProduction=dataqy.value.tmProduction
            inputqy.tMid=dataqy.value.tMid
        }else{
            inputqy.tmProduction=sc.value
        }
}


const formSizeqy = ref<ComponentSize>('default')
const ruleFormRefqy = ref<FormInstance>()
//非空
const rulesqy = reactive<FormRules<RuleForm>>({
  pqyName: [
    { required: true, message: '公司名称不能为空', trigger: 'blur' },
  ],
  tmProduction: [
    { required: true, message: '生产许可证号不能为空', trigger: 'blur' },
  ],
})
const addsqy = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
            axios.post('/Processing/AddProcessingQY',inputqy)
            .then((res)=>{
                sc.value=inputqy.tmProduction
                localStorage.removeItem('sc')
                localStorage.setItem('sc',inputqy.tmProduction)
                //console.log(res.data)
                if(res.data>0){
                    ElMessage({
                        message: '保存成功',
                        type: 'success',
                    })
                    addshowqy.value=false
                    Infoshowsqy()
                    window.location.reload()
                }
            })
    } else {
      console.log('error submit!', fields)
    }
  })
}

// #endregion


//#region 企业照片


const numq=ref([])
//图片
const fileListq = ref<UploadUserFile[]>([])
//显示
const showsq=()=>{
    axios.get('/Processing/GetProcessingImg6?tmid='+localStorage.getItem('tmid'))
    .then((res)=>{
        //console.log(res.data)
        numq.value=res.data.length
        if (Array.isArray(res.data)) {
        fileListq.value = res.data.map((image) => ({
          name: image.pImgId ,  
          url: image.pImgurl
        }));
      } else {
        console.error('Unexpected response data format:', res.data);
      }
    })
}
const computedHeightq=computed(()=> {
    showsq()
    return {
        height: num.value < 7 ? '230px' : '390px', // 直接返回字符串
        alignItems: 'center',
        margin: '0 auto',
        float: 'left',
        width: '100%',
      };
    })

const lisq = computed(() => {
  return fileListq.value.length > 9 ? '' : 'http://182.92.209.50:8001/api/TraceManage/GetImage';
});
// 判断是否禁用上传按钮
//const isUploadDisabled = computed(() => fileList.value.length > 9);
const dialogImageUrlq = ref('')
const dialogVisibleq = ref(false)
//删除图片
const handleRemoveq: UploadProps['onRemove'] = (url) => {
  console.log(url.name)
    axios.post('/Processing/DelProcessingImg?ids='+url.name)
    .then((res)=>{
        //console.log(res.data,num.value)
        if(numq.value==7){
          showsq()//相关资质
      }
    })
}
//预览图片处理事件
const handlePictureCardPreviewq: UploadProps['onPreview'] = (uploadFile) => {
  dialogImageUrlq.value = uploadFile.url!
  dialogVisibleq.value = true
}
//上传成功后
const handleUploadSuccessq=(url)=>{
  //console.log(url)
  axios.post('/Processing/AddProcessingImg6',{
    tMid:localStorage.getItem('tmid'),
    pImgurl:url,
    addName:"张三"
  })
  .then((res)=>{
    //console.log(res.data)
    if(numq.value==6){
    showsq()//动检证
    }
  })
}
//上传失败
const handleUploadErrorq = (err) => {
    showsq()
    if(numq.value==9){
        ElMessage.error(`最多上传9张图片`);
    }else{
        ElMessage.error(`图片上传失败，请重试！`);
    }
};

//#endregion






</script>